import uuid
from typing import Any, TypeVar

from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession

from recruit.adapter.database.models import User, Base

ModelTest = TypeVar('ModelTest')


async def delete_user(
        session: AsyncSession,
        user_id: uuid.UUID
) -> None:
    user = await session.get(User, user_id)
    await session.delete(user)
    await session.commit()


async def get_resume(
        session: AsyncSession,
        model: type[Base],
        id: uuid.uuid4()
) -> Base | None:
    stmt = select(model).filter_by(id=id)
    return (await session.execute(stmt)).scalar_one_or_none()


def check_attr_model(model: Base, data: dict[str, Any]) -> None:
    for key, value in data.items():
        assert getattr(model, key) == value


def check_get_one(
        model: Base,
        model_test: ModelTest,
        keys: tuple[str, ...]
) -> None:
    for key in keys:
        assert getattr(model, key) == getattr(model_test, key)
